package com.ycbj.android.app.fragment;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ycbj.android.app.R;

/**
 * Created by zed on 2017/5/2/0002.
 */
public abstract class BaseFragment extends Fragment{

    private View mRootView;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (mRootView == null) {
            mRootView = inflater.inflate(R.layout.fragment_base, container, false);
            ImageView imageView = (ImageView) mRootView.findViewById(R.id.fragment_base_title_iv);
            TextView textView = (TextView) mRootView.findViewById(R.id.fragment_base_title_tv);

            ViewGroup childContainer = (ViewGroup) mRootView.findViewById(R.id.fragment_base_child_container);

            int childLayout = getContentLayoutRes();

            View childView = inflater.inflate(childLayout, childContainer, true);
            //初始化 子fragment中的布局、控件
            initView(childView,imageView,textView);
        }

        return mRootView;
    }

    /**
     *
     * @param childView      用来findViewById ，也就是 getContentLayoutRes 得到的对应的布局
     * @param imageView
     * @param textView
     */
    protected abstract void initView(View childView, ImageView imageView, TextView textView);

    /**
     * 让子类去实现，返回一个中间区域所需要的布局资源，
     * 父类在 onCreateView 会把这个资源填充出来并添加到 R.id.fragment_base_child_container 中间去
     * @return
     */
    public abstract int getContentLayoutRes();

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onStop() {
        super.onStop();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }
}
